package com.hyy.blogtest.common.pojo;

import com.hyy.blogtest.common.enums.ResultStatus;
import lombok.Data;

@Data
public class Result<T>{

        private int code;//响应的状态码代表是否成功
        private String errMsg;//错误信息
        private T data;//传递的数据

        public static <T> Result<T> ok(T data) {
            Result<T> result = new Result<T>();
            result.setCode(ResultStatus.SUCCESS.getCode());
            result.setData(data);
            return result;
        }

    public static <T> Result<T> fail(String errMsg) {
        Result<T> result = new Result<T>();
        result.setCode(ResultStatus.FAIL.getCode());
        result.setErrMsg(errMsg);
        result.setData(null);
        return result;
    }

    public static <T> Result<T> fail(String errMsg,T data) {
        Result<T> result = new Result<T>();
        result.setCode(ResultStatus.FAIL.getCode());
        result.setErrMsg(errMsg);
        result.setData(data);
        return result;
    }

}
